package com.xiaohe66.web.domain.im.service;

import com.xiaohe66.web.domain.account.value.AccountId;
import com.xiaohe66.web.domain.im.agg.ImUser;
import com.xiaohe66.web.domain.im.repository.ImUserRepository;
import com.xiaohe66.web.domain.im.value.ImUserPublicKey;
import com.xiaohe66.web.domain.sys.sec.service.SecurityService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author xiaohe
 * @since 2023-09-07 16:22
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class ImUserService {

    private final ImUserRepository imUserRepository;
    private final SecurityService securityService;

    public void changeCurrentImUserPublicKey(ImUserPublicKey publicKey) {

        AccountId currentAccountId = securityService.getCurrentAccountId();

        ImUser currentImUser = imUserRepository.getByCreateId(currentAccountId);

        currentImUser.changePublicKey(publicKey);

        imUserRepository.save(currentImUser);
    }

    public ImUser getByCurrentUser() {

        AccountId currentAccountId = securityService.getCurrentAccountId();

        return imUserRepository.getByCreateId(currentAccountId);
    }
}
